(function() {"use strict";var __module = CC_EDITOR ? module : {exports:{}};var __filename = 'preview-scripts/assets/Script/StartGameView.js';var __require = CC_EDITOR ? function (request) {return cc.require(request, require);} : function (request) {return cc.require(request, __filename);};function __define (exports, require, module) {"use strict";
cc._RF.push(module, '1cecaG33C5HDrdnZIQ2fR1G', 'StartGameView', __filename);
// Script/StartGameView.js

"use strict";

var _PlatformUtil = require("./PlatformUtil");

var _PlatformUtil2 = _interopRequireDefault(_PlatformUtil);

var _NumberView = require("./NumberView");

var _NumberView2 = _interopRequireDefault(_NumberView);

var _XmlHttpTool = require("./XmlHttpTool");

var _XmlHttpTool2 = _interopRequireDefault(_XmlHttpTool);

var _allVariable = require("./allVariable");

var _allVariable2 = _interopRequireDefault(_allVariable);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

cc.Class({

    extends: cc.Component,

    properties: {

        startGameBtn: cc.Button,
        numberCompontent: _NumberView2.default,
        energyCompontent: _NumberView2.default,
        bgMusicSound: {
            default: null,
            type: cc.AudioClip
        },
        topView: cc.Node,
        logonode: cc.Node,
        wordListView: cc.Node,
        wordShowView: cc.Node,
        friendListView: cc.Node,
        bageAllScrollView: cc.Node,
        inviteBtn: cc.Button,
        rankBtn: cc.Button,
        moreBtn: cc.Button,
        shopBtn: cc.Button,
        moreContentView: cc.Node,
        showHubProjess: cc.Node,
        SvprogressPrefab: cc.Prefab,
        userEnergy: cc.Integer,
        addenergyBtn: cc.Button,
        insufficientAllView: cc.Node,
        insufficientClose: cc.Button,
        playNowBtn: cc.Button,
        exchangeEnergyView: cc.Node,
        isshareSuccess: cc.Boolean

    },

    enterGameViewClick: function enterGameViewClick() {
        var _this2 = this;

        sdkbox.PluginAdMob.hide("home");
        if (this.userEnergy > 0) {
            var changebig2 = cc.scaleTo(0.2, 1.1);

            var finish = cc.callFunc(function () {

                var changesmail2 = cc.scaleTo(0.1, 1.0);
                this.startGameBtn.node.runAction(changesmail2);
            }, this);

            var seq = cc.sequence(changebig2, finish);

            this.startGameBtn.node.runAction(seq);

            cc.director.loadScene("GameSence", function () {

                var mainNode = cc.find("Canvas/backgroundtop");

                mainNode.getComponent("backgrould").onAgainSence();
            });
        } else {

            console.log("体力不足不能开始游戏");
            if (cc.isValid(this.showHubProjess)) {
                this.showHubProjess.destroy();
            }
            this.showHubProjess = cc.instantiate(this.SvprogressPrefab);
            this.node.addChild(this.showHubProjess);
            this.showHubProjess.getComponent('SVProgressView').init("Insufficient energy unable to participate");

            var _finish = cc.callFunc(function () {

                _this2.showHubProjess.destroy();
            }, this);
            var action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(0.5), cc.fadeOut(1), _finish);
            this.showHubProjess.runAction(action);
        }
    },

    onLoad: function onLoad() {

        if (_allVariable2.default.isMusicPlaying) {} else {

            this.current = cc.audioEngine.play(this.bgMusicSound, true, 1);
            _allVariable2.default.isMusicPlaying = true;
        }

        var changebig2 = cc.scaleTo(0.2, 1.2);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.logonode.runAction(changesmail2);
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.logonode.runAction(seq);

        var self = this;
        self.kHomeBanner = "home";
        self.kGameOverAd = "gameover";
        self.kRewardedAd = "rewarded";

        var initSDK = function initSDK() {
            if ("undefined" == typeof sdkbox) {
                console.log("sdkbox is not exist");
                return;
            }

            if ("undefined" != typeof sdkbox.PluginAdMob) {
                var plugin = sdkbox.PluginAdMob;
                plugin.setListener({
                    adViewDidReceiveAd: function adViewDidReceiveAd(name) {
                        console.log('adViewDidReceiveAd name=' + name);
                        if (name == self.kHomeBanner) {
                            plugin.show(name);
                        }
                    },
                    adViewDidFailToReceiveAdWithError: function adViewDidFailToReceiveAdWithError(name, msg) {
                        console.log('adViewDidFailToReceiveAdWithError name=' + name + ' msg=' + msg);
                    },
                    adViewWillPresentScreen: function adViewWillPresentScreen(name) {
                        console.log('adViewWillPresentScreen name=' + name);
                    },
                    adViewDidDismissScreen: function adViewDidDismissScreen(name) {
                        console.log('adViewDidDismissScreen name=' + name);
                        plugin.cache(name);
                    },
                    adViewWillDismissScreen: function adViewWillDismissScreen(name) {
                        console.log('adViewWillDismissScreen=' + name);
                    },
                    adViewWillLeaveApplication: function adViewWillLeaveApplication(name) {
                        console.log('adViewWillLeaveApplication=' + name);
                    },
                    reward: function reward(name, currency, amount) {

                        console.log('reward=' + name + ' ' + currency + ' ' + amount);
                        console.log('totalAmount=' + self.totalAmount);
                    }
                });
                plugin.init();

                if ("undefined" != typeof plugin.deviceid && plugin.deviceid.length > 0) {
                    console.log(">>>>{0}".format(plugin.deviceid));
                    plugin.setTestDevices(plugin.deviceid);
                }
            } else {
                printf("no plugin init");
            }
        };

        initSDK();

        sdkbox.PluginAdMob.show("home");
    },


    insufficientCloseClick: function insufficientCloseClick() {

        this.insufficientAllView.active = false;
    },

    getUserInfoHttp: function getUserInfoHttp() {
        console.log("获取用户信息");
        var that = this;
        _XmlHttpTool2.default.NhttpPost("/marmot/user_info", {}, function (res) {

            console.log("用户信息", JSON.stringify(res));

            var stars = parseInt(res["ticket_num"]);
            var energy = parseInt(res["energy_num"]);
            that.userEnergy = energy;
            that.numberCompontent.setText(stars);
            that.energyCompontent.setText(energy);
        });
    },

    addEnergyClick: function addEnergyClick() {
        console.log("增加体力");

        this.exchangeEnergyView.active = true;
    },

    chargeEnergyClick: function chargeEnergyClick() {

        var that = this;
        _XmlHttpTool2.default.NhttpPost("/marmot/star2energy", {}, function (res) {
            console.log("兑换体力成功", JSON.stringify(res));
            that.getUserInfoHttp();

            if (cc.isValid(that.showHubProjess)) {
                that.showHubProjess.destroy();
            }
            that.showHubProjess = cc.instantiate(that.SvprogressPrefab);
            that.node.addChild(that.showHubProjess);
            that.showHubProjess.getComponent('SVProgressView').init("Increase energy a little");

            var finish = cc.callFunc(function () {

                that.showHubProjess.destroy();
            }, that);
            var action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(0.5), cc.fadeOut(1), finish);
            that.showHubProjess.runAction(action);
        }, function (failres) {
            console.log("兑换体力失败", JSON.stringify(failres));
            that.insufficientAllView.active = true;
        });
    },

    inviteShare: function inviteShare() {

        console.log("邀请好友一起玩ss");

        var changebig2 = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.inviteBtn.node.runAction(changesmail2);
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.inviteBtn.node.runAction(seq);

        var that = this;

        _XmlHttpTool2.default.NhttpPost("/wxmp/marmot/share_msg", { "type": "link", "link": "http://www.taoqi001.com/", "title": "TapTapMoles", "text": "Best Game Engine" }, function (res) {

            console.log('分享成功', JSON.stringify(res));
            that.shareLink(res);

            var _this = that;
            _XmlHttpTool2.default.NhttpPost("/wxmp/marmot/share", {}, function (shareres) {

                console.log('分享加体力', JSON.stringify(shareres));
                _this.isshareSuccess = shareres["success"];
                _this.getUserInfoHttp();
            });
        }, function (failres) {
            console.log('分享失败', failres);
        });
    },

    shareLink: function shareLink(sharedic) {

        console.log('分享跳转', JSON.stringify(sharedic));
        if (sdkbox.PluginFacebook.isLoggedIn()) {
            console.log('分享跳转用户已经登录');
            var info = new Object();
            info.type = sharedic["type"];
            info.link = sharedic["link"];
            info.title = sharedic["title"];
            info.text = sharedic["text"];
            info.image = sharedic["image"];
            sdkbox.PluginFacebook.dialog(info);
        } else {
            console.log('分享跳转用户未登录');
            sdkbox.PluginFacebook.init();
            sdkbox.PluginFacebook.login();
        }
        var _this = this;
        sdkbox.PluginFacebook.setListener({
            onLogin: function onLogin(isLogin, msg) {},
            onGetUserInfo: function onGetUserInfo(userInfo) {

                var info = new Object();
                info.type = sharedic["type"];
                info.link = sharedic["link"];
                info.title = sharedic["title"];
                info.text = sharedic["text"];
                info.image = sharedic["image"];
                sdkbox.PluginFacebook.dialog(info);
            },


            onSharedSuccess: function onSharedSuccess(data) {},
            onSharedFailed: function onSharedFailed(data) {
                console.log("share onSharedFailed");
            },
            onSharedCancel: function onSharedCancel() {

                console.log("share canceled");

                if (cc.isValid(_this.showHubProjess)) {
                    _this.showHubProjess.destroy();
                }
                _this.showHubProjess = cc.instantiate(_this.SvprogressPrefab);
                _this.node.addChild(_this.showHubProjess);
                if (_this.isshareSuccess == true) {
                    _this.showHubProjess.getComponent('SVProgressView').init("Share success and gain 1 energy");
                } else {
                    _this.showHubProjess.getComponent('SVProgressView').init("Only share 3 times a day");
                }

                var finish = cc.callFunc(function () {

                    _this.showHubProjess.destroy();
                }, _this);
                var action = cc.sequence(cc.fadeIn(0.6), cc.delayTime(3), cc.fadeOut(1), finish);
                _this.showHubProjess.runAction(action);
            }

        });
    },

    rankView: function rankView() {

        console.log("排行榜");

        var changebig2 = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.rankBtn.node.runAction(changesmail2);
            this.wordListView.active = true;
            this.wordShowView.getComponent("ListScrollView").init();
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.rankBtn.node.runAction(seq);
    },

    bageView: function bageView() {

        console.log("兑换包裹");
    },

    moreView: function moreView() {

        console.log("更多");

        var changebig2 = cc.scaleTo(0.2, 1.1);

        var finish = cc.callFunc(function () {

            var changesmail2 = cc.scaleTo(0.1, 1.0);
            this.moreBtn.node.runAction(changesmail2);
            this.moreContentView.getComponent("bageScrollView").init();
            this.bageAllScrollView.active = true;
        }, this);

        var seq = cc.sequence(changebig2, finish);

        this.moreBtn.node.runAction(seq);
    },

    start: function start() {}
});

cc._RF.pop();
        }
        if (CC_EDITOR) {
            __define(__module.exports, __require, __module);
        }
        else {
            cc.registerModuleFunc(__filename, function () {
                __define(__module.exports, __require, __module);
            });
        }
        })();
        //# sourceMappingURL=StartGameView.js.map
        